import Role from "./Role";

const {ccclass, property} = cc._decorator;

@ccclass
export default class Enemy extends Role {
    camp = "enemy";

    Qstart(){
        this.hpBar.hideText();
    }

    //攻击
    attack(target){
        this.hideBar();
        this.target = target;
        //攻击        
        this.animation.play("2");
    }
   
    AttackAnim(action:string){
        switch(action){
            case "move":
                this.animation.pause();             
                var tp = this.target.node.position.sub(this.node.position).normalize().mul( 50 );
                var a1 = cc.moveTo(0.5,this.target.node.position.sub(tp));
                var a2 = cc.callFunc(()=>{
                    this.target.Beaten();
                    this.animation.resume();
                })
                this.node.runAction(cc.sequence(a1,a2));
            break;
            case "end":                                              
                var a1 = cc.delayTime(0.5);
                 a2 = cc.jumpTo(1,this.originPosition,60,1);
                var a3 = cc.callFunc(()=>{
                    this.animation.play("1");
                    this.RoleEnd();
                })
                this.node.runAction( cc.sequence(a1,a2,a3) );                          
            break;
        }
    }


    /** 被攻击时的动作 */
    Beaten(){
        //敌人被攻击时，脚步倒退
        var a1 = cc.moveBy(0.5,-20,0);
        var a2 = cc.delayTime(0.5);
        var a3 = cc.callFunc(()=>{
            this.SubHpTip(0);
        })
        var a4 = cc.moveBy(0.2,20,0);
        this.node.runAction(cc.sequence(a1,a2,a3,a4));
    }
}
